#include "WorldManager.h"

using namespace std;
using namespace me;

WorldManager::WorldManager()
{
    m_currentWorld = NULL;
}

WorldManager::~WorldManager()
{
    for (unsigned int i = 0 ; i < m_worlds.size() ; i++)
    {
        if (m_worlds[i] != NULL)
            delete m_worlds[i];
    }
}

bool WorldManager::addWorld(me::World* world)
{
    for (unsigned int i=0 ; i < m_worlds.size() ; i++)
    {
        if (world->getName() == m_worlds[i]->getName())
            return false;
    }
    m_worlds.push_back(world);
    return true;
}

bool WorldManager::removeWorld(string name)
{
    for (unsigned int i=0 ; i < m_worlds.size() ; i++)
    {
        if (name == m_worlds[i]->getName())
        {
            m_worlds.erase(m_worlds.begin()+i);
            return true;
        }
    }
    return false;
}

bool WorldManager::setCurrentWorld(string name)
{
    for (unsigned int i=0 ; i < m_worlds.size() ; i++)
    {
        if (name == m_worlds[i]->getName())
        {
            m_currentWorld = m_worlds[i];
            return true;
        }
    }
    return false;
}

me::World* WorldManager::getCurrentWorld()
{
    return m_currentWorld;
}

me::World* WorldManager::getWorld(string name)
{
    for (unsigned int i=0 ; i < m_worlds.size() ; i++)
    {
        if (name == m_worlds[i]->getName())
            return m_worlds[i];
    }
    return NULL;
}
